package pl.edu.mimuw.irs.core.model.analysis;

import java.io.Serializable;

public class Time implements Comparable<Time>, Serializable {

	private static final long serialVersionUID = 6364086432038938936L;
	
	// *** Attributes

	private int value;
	public int getValue() {
		return value;
	}
	public void setValue(int value) {
		this.value = value;
	}
	
	// *** Constructor

	public Time(Time start, Time end) {
		this.value = end.getValue() - start.getValue();
	}
	
	public Time(int value) {
		this.value = value;
	}

	public Time(double value) {
		this(new Double(value).intValue());
	}
	
	public Time() {
		this(0);
	}
	
	// *** Methods
	
	public void add(int value) {
		this.value += value;
	}
	
	public void add(Time time) {
		this.value += time.getValue();
	}

	public void setMax(int timestamp) {
		if (this.value < timestamp) 
			this.value = timestamp;
	}
	
	public void setMax(Time timestamp) {
		setMax(timestamp.getValue());
	}
	
	public Time copy() {
		return new Time(getValue());
	}
	
	@Override
	public String toString() {
		return getClass().getSimpleName() + "(" + getValue() + ")";
	}
	
	@Override
	public int hashCode() {
		return getValue();
	}
	
	@Override
	public boolean equals(Object obj) {
		if (obj != null && obj instanceof Time) {
			Time timestamp = (Time) obj;
			return this.getValue() == timestamp.getValue();
		}
		return false;
	}
	
	@Override
	public int compareTo(Time o) {
		return value - o.value;
	}
}
